﻿using System;
using System.Collections.Generic;
using LCL.LData;

namespace LCL.CodeEngine {
    [Serializable]
    public class TableHost:DatabaseHost {
        private string _tablename;
        private string _tabledescription = "";
        private List<ColumnInfo> _keys;
        private List<TableRelation> _fkeys;
        private List<ColumnInfo> _fieldlist;
        private string _folder;
        /// <summary>
        /// 表名
        /// </summary>
        public string TableName {
            get {
                return this._tablename;
            }
            set {
                this._tablename = value;
            }
        }
        /// <summary>
        /// 表的描述信息
        /// </summary>
        public string TableDescription {
            get {
                return this._tabledescription;
            }
            set {
                this._tabledescription = value;
            }
        }
        /// <summary>
        /// 字段集合
        /// </summary>
        public List<ColumnInfo> Fieldlist {
            get {
                return this._fieldlist;
            }
            set {
                this._fieldlist = value;
            }
        }
        /// <summary>
        /// 主键字段集合
        /// </summary>
        public List<ColumnInfo> Keys {
            get {
                return this._keys;
            }
            set {
                this._keys = value;
            }
        }
        /// <summary>
        /// 外键字段集合
        /// </summary>
        public List<TableRelation> FKeys {
            get {
                return this._fkeys;
            }
            set {
                this._fkeys = value;
            }
        }
        /// <summary>
        /// 所属文件夹
        /// </summary>
        public string Folder {
            get {
                return this._folder;
            }
            set {
                this._folder = value;
            }
        }
        /// <summary>
        /// 自动增长标示列
        /// </summary>
        public ColumnInfo IdentityKey {
            get {
                ColumnInfo result = new ColumnInfo();
                foreach(ColumnInfo current in this.Fieldlist) {
                    if(current.IsIdentity) {
                        result = current;
                    }
                }
                return result;
            }
        }
        public string Now {
            get {
                return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
        }

        public TableHost() {
            _keys = new List<ColumnInfo>();
            _fkeys = new List<TableRelation>();
            _fieldlist = new List<ColumnInfo>();
        }
        public TableHost(string TableName) {
            this._tablename = TableName;
            _keys = new List<ColumnInfo>();
            _fkeys = new List<TableRelation>();
            _fieldlist = new List<ColumnInfo>();
        }
    }
}
